package us.icitap.commandcenter.ui.custom;

import us.icitap.commandcenter.business.ejb.persistence.CallReason;
import us.icitap.commandcenter.business.ejb.persistence.CallStatusEnum;
import us.icitap.commandcenter.business.ejb.persistence.Dispatcher;
import us.icitap.commandcenter.business.ejb.persistence.Grade;
import us.icitap.commandcenter.business.ejb.persistence.UniqueNumber;

import com.vaadin.data.Item;
import com.vaadin.data.Property;
import com.vaadin.shared.ui.label.ContentMode;
import com.vaadin.ui.Label;
import com.vaadin.ui.Table;
import com.vaadin.ui.Table.ColumnGenerator;

public class CustColumnGenerator {

	public static final ColumnGenerator callReasonColumnGenerator = new ColumnGenerator() {
		
		@Override
		public Object generateCell(Table source, Object itemId, Object columnId) {
			final Item item = source.getItem(itemId);
	         final Property prop = item.getItemProperty(columnId);
	         
	         if(prop.getValue() != null){
	        	CallReason b = (CallReason) prop.getValue();
	        	final Label label = new Label(b.getTag());
	        	return label;
	         }
	         else{
	        	 return new Label("");
	         }
		}
	};
	
	
	public static final ColumnGenerator gradeColumnGenerator = new ColumnGenerator() {
		
		@Override
		public Object generateCell(Table source, Object itemId, Object columnId) {
			final Item item = source.getItem(itemId);
	         final Property prop = item.getItemProperty(columnId);
	         
	         if(prop.getValue() != null){
	        	Grade g = (Grade) prop.getValue();
	        	final Label label = new Label(g.getTag());
	        	return label;
	         }
	         else{
	        	 return new Label("");
	         }
		}
	};
	
	public static final ColumnGenerator callStatusColumnGenerator = new ColumnGenerator() {
		
		@Override
		public Object generateCell(Table source, Object itemId, Object columnId) {
			final Item item = source.getItem(itemId);
	         final Property prop = item.getItemProperty(columnId);
	         
	         if(prop.getValue() != null){
	        	CallStatusEnum callStatusEnum = (CallStatusEnum) prop.getValue();
	        	final Label label = new Label(callStatusEnum.toString());
	        	return label;
	         }
	         else{
	        	 return new Label("");
	         }
		}
	};
	
	public static final ColumnGenerator dispatcherColumnGenerator = new ColumnGenerator() {
		
		@Override
		public Object generateCell(Table source, Object itemId, Object columnId) {
			final Item item = source.getItem(itemId);
	         final Property prop = item.getItemProperty(columnId);
	         
	         if(prop.getValue() != null){
	        	Dispatcher dis = (Dispatcher) prop.getValue();
	        	final Label label = new Label(dis.getName());
	        	return label;
	         }
	         else{
	        	 return new Label("");
	         }
		}
	};
	
	public static final ColumnGenerator uniqueNumberColumnGenerator = new ColumnGenerator() {
		
		@Override
		public Object generateCell(Table source, Object itemId, Object columnId) {
			final Item item = source.getItem(itemId);
	         final Property prop = item.getItemProperty(columnId);
	         
	         if(prop.getValue() != null){
	        	UniqueNumber un = (UniqueNumber) prop.getValue();
	        	final Label label = new Label("" + un.getUniqueNumber());
	        	return label;
	         }
	         else{
	        	 return new Label("");
	         }
		}
	};
	
	
	public static final ColumnGenerator htmlColumnGenerator = new ColumnGenerator() {
		
		@Override
		public Object generateCell(Table source, Object itemId, Object columnId) {
			final Item item = source.getItem(itemId);
	         final Property prop = item.getItemProperty(columnId);
	         
	         if(prop.getValue() != null){
	        	final Label label = new Label(prop.getValue().toString(),ContentMode.HTML);
	        	return label;
	         }
	         else{
	        	 return new Label("");
	         }
		}
	};
	

	
	
}
